package com.tang.lts.core.autoconfigure.resolver;

import com.tang.lts.core.autoconfigure.AutoConfigContext;

import java.beans.PropertyDescriptor;

/**
 * @author Tang
 * @classname ClassResolver
 * @description [  ]
 * @date 2022/4/13 21:02
 */
public class ClassResolver extends AbstractResolver {

    public static final ClassResolver INSTANCE = new ClassResolver();

    @Override
    public void resolver(AutoConfigContext autoConfigContext, PropertyDescriptor propertyDescriptor, String includeName) {
        doFilter(autoConfigContext, propertyDescriptor,includeName, new Filter() {
            @Override
            public boolean onCondition(String name, String key, String value) {
                return name.contains(key);
            }

            @Override
            public boolean call(String name, String key, String value) {
                Class<?> aClass = null;
                try {
                    aClass = Class.forName(value);
                } catch (ClassNotFoundException e) {
                    e.printStackTrace();
                }
                writeProperty(autoConfigContext,propertyDescriptor,aClass);
                return false;
            }
        });
    }

}